package Testdemo3.Test1;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:周次煜
 * Date: 2024-05-18
 * Time：20:15
 */
public class MyExceptionTest{
    public static void main (String[ ] args) {
        System.out.print("请输入班级人数：");
        Scanner sca=new Scanner(System.in);
        int n=sca.nextInt();
        try {
            makeClass(n);
            //makeClass(65);
        }catch (MyException ex) {
            System.out.println("捕获自定义异常"+ex);
        }
    }
    static void makeClass(int num) throws MyException{
        System.out.println("调用makeClass方法，人数为"+num+"人。");
        if(num>60)
            throw new MyException("人数过多！");
        System.out.println("人数正常！");
    }
}
class MyException extends Exception{
    MyException(String s){
        super(s);
    }
}